import React, { Component } from 'react';
import './fruiter.css';
import FruiterSearch from './FruiterSearch'
import GotoPage from './GotoPage';
import { withRouter } from "react-router-dom";
import { FruiterCreator, DelBusiness, getAdmin, DelGoods } from '../Redux/ActionCreator';
import { connect } from 'react-redux';
//果农管理右半部分页面
class Fruiter extends Component {
    constructor(props) {
        super(props);
        this.state = {
        };
        this.props.dispatch(FruiterCreator())
    }
    render() {
        return (
            <div className="body_right">
                <div className='right_top'>
                    <p>果农管理 查看商家</p>
                </div>
                <div className='right_middle'>
                    <div className='search_id'>
                        <p>输入查找的内容</p>
                        <FruiterSearch />
                        <div className='fruitertable'>
                            <table border='0' cellpadding='5' cellspacing='0' className='mytable'>
                                <thead>
                                    <tr>
                                        <th>编号</th>
                                        <th>ID</th>
                                        <th>昵称</th>
                                        <th>手机号</th>
                                        <th>邮箱</th>
                                        <th>城市</th>
                                        <th>地址</th>
                                        <th>营业时间</th>
                                        <th>负责人</th>
                                        <th>头像</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {
                                        this.props.fruiterreducer.map((item, index) => {
                                            return (
                                                <tr onClick={
                                                    // this.redirectUrl
                                                    () => this.props.history.push('/goods', { business_id: item.business_id })
                                                }>
                                                    <td>{index + 1}</td>
                                                    <td>{item.business_id}</td>
                                                    <td >{item.business_name}</td>
                                                    <td>{item.business_phone}</td>
                                                    <td>{item.business_email}</td>
                                                    <td>{item.county_id}</td>
                                                    <td>{item.business_address}</td>
                                                    <td>{item.business_time}</td>
                                                    <td>{item.business_header}</td>
                                                    <td id='business_pic'><img key={index} src={`http://www.h5weixin.club:1025/api/image/${item.business_pic}`} /></td>
                                                    <td>
                                                        <button className='delete'
                                                            onClick={() => {
                                                                const adminpwd = prompt('请输入管理员登录密码：')
                                                                if (adminpwd) {
                                                                    this.props.dispatch(DelBusiness(item.business_id, getAdmin(this.props).admin_id, adminpwd))
                                                                }
                                                                return false;
                                                            }}
                                                        >删除</button></td>
                                                </tr>
                                            )
                                        })
                                    }
                                </tbody>
                            </table>
                        </div>
                        {/* 分页 */}
                        <GotoPage />
                    </div>
                </div>
            </div>
        );
    }
    // redirectUrl = () =>{
    //     this.props.redirectUrl();
    // }
}
const mapStateToProps = (state) => ({
    fruiterreducer: state.fruiterreducer
})
export default connect(mapStateToProps)(withRouter(Fruiter));
